<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>LTO object file layout (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="LTO object file layout (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="LTO object file layout (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="LTO.html" rel="up" title="LTO">
<link href="IPA.html" rel="next" title="IPA">
<link href="LTO-Overview.html" rel="prev" title="LTO Overview">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="LTO-object-file-layout"></span><div class="header">
<p>
Next: <a href="IPA.html" accesskey="n" rel="next">IPA</a>, Previous: <a href="LTO-Overview.html" accesskey="p" rel="prev">LTO Overview</a>, Up: <a href="LTO.html" accesskey="u" rel="up">LTO</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="LTO-file-sections"></span><h3 class="section">25.2 LTO file sections</h3>

<p>LTO information is stored in several ELF sections inside object files.
Data structures and enum codes for sections are defined in
<samp>lto-streamer.h</samp>.
</p>
<p>These sections are emitted from <samp>lto-streamer-out.cc</samp> and mapped
in all at once from <samp>lto/lto.cc</samp>:<code>lto_file_read</code>.  The
individual functions dealing with the reading/writing of each section
are described below.
</p>
<ul>
<li> Command line options (<code>.gnu.lto_.opts</code>)

<p>This section contains the command line options used to generate the
object files.  This is used at link time to determine the optimization
level and other settings when they are not explicitly specified at the
linker command line.
</p>
<p>Most options are recorded at a per function level and their setting
restored when processing the functions at link time.  Global options
are composed from options specified at compile time and link time.
How exactly they are combined or mismatches diagnosed is implemented in
<samp>lto-wrapper.cc</samp>:<code>find_and_merge_options</code>.
</p>

</li><li> Symbol table (<code>.gnu.lto_.symtab</code>)

<p>This table replaces the ELF symbol table for functions and variables
represented in the LTO IL.  Symbols used and exported by the optimized
assembly code of &ldquo;fat&rdquo; objects might not match the ones used and
exported by the intermediate code.  This table is necessary because
the intermediate code is less optimized and thus requires a separate
symbol table.
</p>
<p>Additionally, the binary code in the &ldquo;fat&rdquo; object will lack a call
to a function, since the call was optimized out at compilation time
after the intermediate language was streamed out.  In some special
cases, the same optimization may not happen during link-time
optimization.  This would lead to an undefined symbol if only one
symbol table was used.
</p>
<p>The symbol table is emitted in
<samp>lto-streamer-out.cc</samp>:<code>produce_symtab</code>.
</p>

</li><li> Global declarations and types (<code>.gnu.lto_.decls</code>)

<p>This section contains an intermediate language dump of all
declarations and types required to represent the callgraph, static
variables and top-level debug info.
</p>
<p>The contents of this section are emitted in
<samp>lto-streamer-out.cc</samp>:<code>produce_asm_for_decls</code>.  Types and
symbols are emitted in a topological order that preserves the sharing
of pointers when the file is read back in
(<samp>lto.cc</samp>:<code>read_cgraph_and_symbols</code>).
</p>

</li><li> The callgraph (<code>.gnu.lto_.cgraph</code>)

<p>This section contains the basic data structure used by the GCC
inter-procedural optimization infrastructure.  This section stores an
annotated multi-graph which represents the functions and call sites as
well as the variables, aliases and top-level <code>asm</code> statements.
</p>
<p>This section is emitted in
<samp>lto-streamer-out.cc</samp>:<code>output_cgraph</code> and read in
<samp>lto-cgraph.cc</samp>:<code>input_cgraph</code>.
</p>

</li><li> IPA references (<code>.gnu.lto_.refs</code>)

<p>This section contains references between function and static
variables.  It is emitted by <samp>lto-cgraph.cc</samp>:<code>output_refs</code>
and read by <samp>lto-cgraph.cc</samp>:<code>input_refs</code>.
</p>

</li><li> Function bodies (<code>.gnu.lto_.function_body.&lt;name&gt;</code>)

<p>This section contains function bodies in the intermediate language
representation.  Every function body is in a separate section to allow
copying of the section independently to different object files or
reading the function on demand.
</p>
<p>Functions are emitted in
<samp>lto-streamer-out.cc</samp>:<code>output_function</code> and read in
<samp>lto-streamer-in.cc</samp>:<code>input_function</code>.
</p>

</li><li> Static variable initializers (<code>.gnu.lto_.vars</code>)

<p>This section contains all the symbols in the global variable pool.  It
is emitted by <samp>lto-cgraph.cc</samp>:<code>output_varpool</code> and read in
<samp>lto-cgraph.cc</samp>:<code>input_cgraph</code>.
</p>
</li><li> Summaries and optimization summaries used by IPA passes
(<code>.gnu.lto_.&lt;xxx&gt;</code>, where <code>&lt;xxx&gt;</code> is one of <code>jmpfuncs</code>,
<code>pureconst</code> or <code>reference</code>)

<p>These sections are used by IPA passes that need to emit summary
information during LTO generation to be read and aggregated at
link time.  Each pass is responsible for implementing two pass manager
hooks: one for writing the summary and another for reading it in.  The
format of these sections is entirely up to each individual pass.  The
only requirement is that the writer and reader hooks agree on the
format.
</p></li></ul>


<hr>
<div class="header">
<p>
Next: <a href="IPA.html" accesskey="n" rel="next">IPA</a>, Previous: <a href="LTO-Overview.html" accesskey="p" rel="prev">LTO Overview</a>, Up: <a href="LTO.html" accesskey="u" rel="up">LTO</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
